<template>
  <div class="py-15px px-8px">
    <wd-upload
      v-model:file-list="fileList"
      prop="avatar"
      image-mode="aspectFill"
      :action="action"
      multiple
      @change="getImageList"
    />
  </div>
  <wd-toast />
</template>

<script setup lang="ts">
import { findAllImage } from '@/api/draft';
import { ResultCodeEnum } from '@/enums';
import { useUserStore } from '@/store';
import { jump } from '@/utils/common';
import { useToast } from 'wot-design-uni';
import { UploadFile } from 'wot-design-uni/components/wd-upload/types';

const action = `${import.meta.env.VITE_APP_UPLOAD_URL}?id=${useUserStore().userInfo.id}`;

const fileList = ref<UploadFile[]>([]);

const getImageList = async () => {
  const id = useUserStore().userInfo.id;
  if (!id) return jump('/pages/center/login/index');
  const res = await findAllImage(id);
  if (res.code === ResultCodeEnum.SUCCESS) {
    fileList.value = res.data;
  }
};

onShow(() => {
  getImageList();
});

const { success: showSuccess } = useToast();
</script>

<style lang="scss" scoped></style>
